<?php
namespace app\service;

use app\model\AdminRoleModel;

class AdminRoleService
{
    protected $model;
    
    public function __construct()
    {
        $this->model = new AdminRoleModel;
    }
    
    public function list($params)
    {
        $query = $this->model->newQuery();
        
        // 构建查询条件
                if (!empty($params['name'])) {
            $query->where('name', 'like', str_replace('?', $params['name'], '%?%'));
        }
        if (!empty($params['slug'])) {
            $query->where('slug', 'like', str_replace('?', $params['slug'], '%?%'));
        }
        if (!empty($params['status'])) {
            $query->where('status', '=', str_replace('?', $params['status'], '?'));
        }

        
        return $query->paginate($params['page_size'] ?? 15);
    }
    
    public function create($data)
    {
        return $this->model->create($data);
    }
    
    public function update($id, $data)
    {
        $model = $this->model->findOrFail($id);
        return $model->update($data);
    }
    
    public function delete($id)
    {
        return $this->model->destroy($id);
    }
    
    public function find($id)
    {
        return $this->model->findOrFail($id);
    }

    public function batchDelete($ids)
    {
        return $this->model->destroy($ids);
    }
} 